package com.itqf.Controller;

import com.github.pagehelper.PageInfo;
import com.itqf.Enum.CodeEnum;
import com.itqf.Service.Topic.TopicService;
import com.itqf.Util.DTO.ResultDTO;
import com.itqf.Util.myPageInfo;
import com.itqf.entity.Rotationchart;
import com.itqf.entity.Topic;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/huileme/a/m/JingPinTopController")
public class JingPinTopController {
    @Resource
    private TopicService topicService;


    @RequestMapping(value = "/jingpintop",method = RequestMethod.GET)
    @ResponseBody
    /**
        * @Description:
        * @Param: []
        * @return: java.util.List<com.itqf.entity.Topic>
        * @Author: 赵渊
        * @Date: 20:22
        */ //精品资料，今日推荐接口+今日推荐轮播图接口
    public ResultDTO<Map> getJingpinTopJson()
    {
      List<Topic> list=topicService.findtopics();
        List<Rotationchart> rotationchartList = topicService.getrotationchart();
        Map map=new HashMap();
        map.put("topiclist",list);
        map.put("rotationchartlist",rotationchartList);
        ResultDTO resultDT=new ResultDTO();
      if (!list.isEmpty())
      {
       resultDT.setData(map);
       resultDT.setCode(CodeEnum.selectsuccess.getCode());
       resultDT.setMessage(CodeEnum.selectsuccess.getMsg());
      }else
      {
          resultDT.setData(map);
          resultDT.setCode(CodeEnum.selecterror.getCode());
          resultDT.setMessage(CodeEnum.selecterror.getMsg());
      }

      return resultDT;
    }

    @RequestMapping(value = "/chuzhongzhenti",method = RequestMethod.GET)
    @ResponseBody
    /**
        * @Description:
        * @Param: [pageindex]
        * @return: com.github.pagehelper.PageInfo
        * @Author: 赵渊
        * @Date: 20:22
        */ //精品资料，初中真题接口
    public ResultDTO<PageInfo> getchuzhongzhenti(@RequestParam(defaultValue = "1") int pageindex)
    {
       PageInfo<Topic> pageInfo=topicService.findchuzhongtops(pageindex, myPageInfo.PAGESIZE);

       ResultDTO resultDTO=new ResultDTO();

       if (!pageInfo.getList().isEmpty())
       {
           resultDTO.setData(pageInfo);
           resultDTO.setMessage(CodeEnum.selectsuccess.getMsg());
           resultDTO.setMessage(CodeEnum.selectsuccess.getMsg());
       }else{

           resultDTO.setMessage(CodeEnum.selecterror.getMsg());
           resultDTO.setMessage(CodeEnum.selecterror.getMsg());
       }

       return resultDTO;
    }
    @RequestMapping(value = "/gaozhongzhenti",method = RequestMethod.GET)
    @ResponseBody
    /** 
        * @Description:
        * @Param: [pageindex] 
        * @return: com.itqf.Util.DTO.ResultDTO<com.github.pagehelper.PageInfo<com.itqf.entity.Topic>> 
        * @Author: 赵渊
        * @Date: 20:48
        */
    public ResultDTO<PageInfo> getgaozhongzhenti(@RequestParam(defaultValue = "1") int pageindex)
    {
        PageInfo<Topic> pageInfo=topicService.findgaozhongtops(pageindex, myPageInfo.PAGESIZE);

        ResultDTO resultDTO=new ResultDTO();

        if (!pageInfo.getList().isEmpty())
        {
            resultDTO.setData(pageInfo);
            resultDTO.setMessage(CodeEnum.selectsuccess.getMsg());
            resultDTO.setMessage(CodeEnum.selectsuccess.getMsg());
        }else{

            resultDTO.setMessage(CodeEnum.selecterror.getMsg());
            resultDTO.setMessage(CodeEnum.selecterror.getMsg());
        }

        return resultDTO;
    }

}
